<template>
  <div class="operatorLog" >
    <dynamic-load-data ref="dynamicLoadData" :loading="logLoading" :dynamic-data="logData" />
    <div v-if="!logLoading && !logData.length" class="not-data">
      <el-empty description="暂无数据" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue"
import { designerStore } from 'src/stores/designerTool/designerTool'
import DynamicLoadData from '../../components/dynamicLoadData.vue'
import { ElMessageBox } from 'element-plus'
import { getlogs } from 'src/api/designerTool'
import { useRouter } from 'vue-router';
const router = useRouter()
const store = designerStore()
const props = defineProps({
  idConfig: {
    type: Object
  }
})
const title = ref('算子运行日志')
const rowId = ref('')
const logData = ref('')
const logLoading = ref(false)
const experimentsOperator=ref('')

function init(str:string) {
  experimentsOperator.value=str
  getInstancesLog()
}
function getInstancesLog() {
  logData.value = ''
  logLoading.value = true
  let filepathStr = `error_${store.operator_id}.log`
  if (store.allOperator.length > 0) {
    store.allOperator.forEach((ele: any) => {
      if (ele.id == store.operator_id) {
        if (ele.status == 'success') {
          filepathStr = `output_${store.operator_id}.log`
        }
      }
    })
  }
  let workflow_id=store.workflow_id
  let instance_id=store.instanceId
  if (store.LeftTabsState == false && store.experiments_id.workflow_id > 0) {
    workflow_id = store.experiments_id.workflow_id
    instance_id =store.experiments_id.id
    if(experimentsOperator.value=='success'){
      filepathStr = `output_${store.operator_id}.log`
    }
  }


  getlogs(store.project_id, workflow_id, instance_id, {
    filepath: filepathStr
    // start_time: '',
    // end_time: this.$moment(new Date()).format('YYYYMMDDHHmmss')
  }).then((res: any) => {
    logData.value = res.data.replace(/\n/g, '<br>')
  }).catch((error) => {
    console.log(error)
  }).finally(() => {
    logLoading.value = false
  })
}
defineExpose({ init })
</script>

<style lang="scss" scoped>
.operatorLog {
  height: 100%;
  position: relative;

  .not-data {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: grid;
  }
}
</style>
